<?php
namespace web\admin\controller;

class Typeattr extends Common{
	private $db;
	public function __construct()
	{
		parent::__construct();
		$this->db = new \system\model\Typeattr();
	}
	public function index(){
		$data = $this->db->getAll();
		View::with('data',$data);
		View::make();
	}
	public function store(){
		if (IS_POST){
			//如果添加不通过
			if(!$this->db->store()){
				//获取错误
				message($this->db->getError(),'back','error');
			}else{
				message('添加成功',u('index',['tid'=>$_POST['tid']]),'success');
			}
		}
		View::make();
	}
	public function edit(){
		if (IS_POST){
			if($this->db->edit()){
				message('修改成功',u('index',['tid'=>$_POST['tid']]),'success');
			}else{
				message($this->db->getError(),'back','error');
			}
		}
		$oldData=$this->db->where('taid',$_GET['taid'])->first();
		//分配变量并显示
		View::with('oldData',$oldData);
		View::make();
	}
	/**
	 * 删除
	 */
	public function del(){
		$taid = q('get.taid',0,'intval');
		$this->db->where('taid',$taid)->delete();
		message('操作成功',u('index'),'success');
	}

}
